import * as winston from 'winston'

type Winston = typeof winston

class WxApiLogger {

  private logLevel: LogLevel = 'info'
  private winstonInstance!: Winston
  constructor(winstonInstance: Winston) {
    this.winstonInstance = winstonInstance
    this.init()
  }

  public log(logLevel: LogLevel, msg: string) {
    this.logLevel = logLevel
    this.winstonInstance.log(this.logLevel, msg)
  }

  private init() {

    this.winstonInstance.configure({
      level: this.logLevel,
      transports: [
        new winston.transports.Console({
          format: winston.format.combine(
            winston.format.colorize(),
            winston.format.simple()
          )
        })
      ]
    })

  }

}

const wxApiLogger = new WxApiLogger(winston)
export default wxApiLogger
